package judesart.app.client.facebook;

import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NodeList;

public class FbUtil {

    public static void setOgMeta(Element element, String title, String image,
            String url, String description) {
    	Log.debug(" > setOgMeta");
        NodeList<Element> metas = element.getOwnerDocument().getElementsByTagName(
                "meta");
        for (int i = 0; i < metas.getLength(); i++) {
            Element meta = metas.getItem(i);
            String ogprop = meta.getAttribute("property");
//            Log.debug(" > meta [" + ogprop + "]:["
//                    + meta.getAttribute("content") + "]");
            if ("og:title".equals(ogprop)) {
                meta.setAttribute("content", title);
            }
            if ("og:image".equals(ogprop)) {
                meta.setAttribute("content", image);
            }
            if ("og:url".equals(ogprop)) {
                meta.setAttribute("content", url);
            }
            if ("of:description".equals(ogprop)) {
                meta.setAttribute("content", description);
            }
//            Log.debug(" < meta [" + ogprop + "]:["
//                    + meta.getAttribute("content") + "]");
        }
    	Log.debug(" < setOgMeta");
    }

    public static String like(String extraPath) {
        String ilike = "<fb:like href=\"http://www.judithshaylor.com/rd/" + extraPath + "\""
                + " show_faces=\"false\" share=\"true\" width=\"300\" ref=\"" + extraPath
                + "\"></fb:like>";
        return ilike;
    }

    public static native String parseFBML(String id) /*-{
        $wnd.FB.XFBML.parse($doc.getElementById(id));
    }-*/;
}
